package cn.pugle.base;


import org.apache.hadoop.util.StringUtils;

import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;


/**
 * Created by tzp on 16-3-4.<br/>
 *  UTF-8 ISO
 * 内存中的(int)'þ'是什么
 * utf-8编码成几
 * iso编码成几
 */
public class TestUTFISO {
    public static void main(String[] args) {
        String cxf = "þ";
        String cxf1 = "a\u00feb\u00fec";
        System.out.println((int) 'þ');
        try {
            System.out.println(StringUtils.byteToHexString(cxf1.getBytes("UTF-8")));
            System.out.println(StringUtils.byteToHexString(cxf1.getBytes("ISO-8859-1")));
            System.out.println(Byte.MAX_VALUE + "\n--------------------");
            byte[] bytes = cxf1.getBytes("ISO-8859-1");//数据
            String s = new String(bytes, "UTF-8");//按错误的UTF-8读入.
            System.out.println(s);
            System.out.println((char)65533);

            System.out.println(s.split(Pattern.quote("\u00ef\u00bf\u00bd"))[0]);
            System.out.println(s.split(Pattern.quote("\ufffd"))[0]);
            System.out.println(StringUtils.byteToHexString(s.getBytes("UTF-8")));

            String ss = new String(s.getBytes("UTF-8"), "ISO-8859-1");//再编码回去,按ISO读入
            System.out.println(ss);
            System.out.println(StringUtils.byteToHexString(ss.getBytes("ISO-8859-1")));
            System.out.printf("%d\n", 0xbfbd);
            System.out.printf("%x\n", 65533);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }
}
